package puzzle.projecteuler.p100;

public class Problem040 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println(d(1)*d(10)*d(100)*d(1000)*d(10000)*d(100000)*d(1000000));
	}

	public static int d(int n) {
		
		//step 1
		//9*1, 90*2, 900*3, ...
		int t = n;
		int x = 9;
		int y = 1;
		while (true) {
			 if (t > x*y) {
				 t -= x*y;
				 x *= 10;
				 y ++;
			 } else {
				 break;
			 }
		}
		//step 2
		//get actual number
		x = (int)Math.floor(Math.pow(10, y-1));
		if (t%y == 0) {
			int number = x + t/y - 1;
			int index = t-1;
			return (String.valueOf(number).charAt(index)-'0'); 
		} else {
			int number = x + t/y;
			int index = t%y-1;
			return (String.valueOf(number).charAt(index)-'0'); 
		}
	}
}
